package com.zjf.carpark.controller;


import com.zjf.carpark.entities.TAdvise;
import com.zjf.carpark.service.TAdviseService;
import com.zjf.carpark.utils.Page;
import com.zjf.carpark.utils.ResponseData;
import com.zjf.carpark.vo.TAdviseRequsetVO;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

import java.util.List;

import static com.zjf.carpark.utils.CodeAndMessage.CODE200;
import static com.zjf.carpark.utils.CodeAndMessage.SUCCESS;

/**
 * (TAdvise)表控制层
 *
 * @author makejava
 * @since 2020-05-12 11:26:47
 */
@RestController
@RequestMapping("tAdvise")
public class TAdviseController {
    /**
     * 服务对象
     */
    @Resource
    private TAdviseService tAdviseService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public TAdvise selectOne(Integer id) {
        return this.tAdviseService.queryById(id);
    }

    /**
     * 建议的分页查询
     *
     * @param page
     * @return
     */
    @PostMapping("selectByPage")
    public ResponseData selectByPage(@RequestBody Page page) {
        List<TAdvise> tAdvises = tAdviseService.queryAllByLimit(0, page.getLimit());
        ResponseData responseData = new ResponseData(CODE200, SUCCESS);
        responseData.putDataValue("advises", tAdvises);
        return responseData;
    }

    /**
     * 新增建议
     *
     * @param tAdvise
     * @return
     */
    @PostMapping("insert")
    public ResponseData insert(@RequestBody TAdvise tAdvise) {
        TAdvise insert = tAdviseService.insert(tAdvise);

        return new ResponseData(CODE200, SUCCESS);
    }

    /**
     * 修改建议
     *
     * @param tAdvise
     * @return
     */
    @PostMapping("update")
    public ResponseData update(@RequestBody TAdvise tAdvise) {
        TAdvise update = tAdviseService.update(tAdvise);

        return new ResponseData(CODE200, SUCCESS);
    }
}